<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" isELIgnored="false"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"></c:set>

    <%@ include file="../layout/header.jsp" %>
	<!-- 主体部分开始 -->
	<div class="container bs-docs-container" style="margin-top:10px;">
		<div class="row">
			<h1>主页</h1>
			<div class="bs-docs-section">
				<c:forEach var="obj" items="${message}">
					<div class="bs-callout bs-callout-info" id="callout-type-b-i-elems">
						<h4 style="float:left;">${obj.user.realName}&nbsp;&nbsp;${obj.title}</h4>
						<h4 style="float:right;"><fmt:formatDate value="${obj.createDate}" pattern="yyyy-MM-dd hh:mm:ss"/></h4>
						<p style="clear:both;">${obj.content}</p>
						<p style="text-align:right;">
							<c:if test="${loginUser.id eq obj.user.id}">
								<a class="btn btn-warning" href="#" onclick="edit('${obj.id}','${obj.title}','${obj.content}');">编辑</a>
							</c:if>
							<c:if test="${loginUser.id eq obj.user.id or loginUSer.role.id eq 1}">
								<a class="btn btn-danger"  href="${ctx}/message.do?type=delete&&id=${obj.id}">删除</a>
							</c:if>
							<c:if test="${loginUser.role.id eq 1}">
								<c:if test="${obj.status eq 0}">
									<a class="btn btn-primary" href="${ctx}/message.do?type=stop&&id=${obj.id}">禁用</a>
								</c:if>
								<c:if test="${obj.status eq 1}">
									<a class="btn btn-info" href="#">启用</a>
								</c:if>
							</c:if>
							<a class="btn btn-success" type="button" href="${ctx}/message.do?type=zan&&id=${obj.id}">
							  	点赞 <span class="badge">${obj.zan}</span>
							</a>
						</p>
					</div>
				</c:forEach>
			</div>		
		</div>
		
		
		<hr>
		<div class="row">
			<form id="formMessage" action="${ctx}/message.do?type=add" method="post"  onsubmit="return validate2();">
				<input type="hidden" id="id" name="id">
				<div class="form-group">
					<label for="title">标题</label>
					<span style="color: red;">&nbsp;&nbsp;${messageResult}</span>
					<input type="text" class="form-control" id="title" name="title" placeholder="标题">
				</div>
				<div class="form-group">
					<label for="conter">内容</label> 
					<textarea rows="5" class="form-control" id="content" name="content" placeholder="你先说点什么"></textarea>
				</div>
				<button id="btnSubmit" type="submit" class="btn btn-primary">发表留言</button>
				<button type="reset" class="btn btn-default">重置</button>
			</form>
		</div>
	</div>
	<!-- 主体部分结束 -->
	<%@ include file="../layout/footer.jsp" %>
   


	<script type="text/javascript">
    	function edit(id,title,content){
    		/* 获取参数 *//*  显示到表单中*//*  */
    		$("#id").val(id);
    		$("#title").val(title);
    		$("#content").val(content);
    		/*  修改表单的action和提交按钮的脚本*/
    		$("#formMessage").attr("action","${ctx}/message.do?type=edit");
    		/* alert(${"#formMessage"}.attr("action")); */
    		$("#btnSubmit").text("保存留言");
    		/* alert(${"#btnSubmit"}.text()); */
    	}	
	    
	
    	function validate2(){
    		var title = $("#title").val();
    		var content = $("#content").val();
    		var loginUserInfo = $("#loginUserInfo").text();
    		if(title ==null || title.length < 3){
    			alert("留言标题长度不能小于3！");
    			return false;
    		}
    		if(content ==null || content.length < 3){
    			alert("留言内容长度不能小于3！");
    			return false;
    		}
    		if(loginUserInfo ==null || loginUserInfo.length < 1){
    			alert("请先登录！");
    			return false;
    		}
    		return true;
    	}
    </script>





















